package com.ts.learning.service;

import com.ts.framework.domain.course.TeachplanMediaPub;
import com.ts.framework.domain.learning.respones.GetMediaResult;
import com.ts.framework.exception.ExceptionCast;
import com.ts.framework.model.response.CommonCode;
import com.ts.learning.config.CourseLearningClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseLearningService {
    @Autowired
    private CourseLearningClient courseLearningClient;

    //获取课程学习视频
    public GetMediaResult getmedia(String courseId, String teachplanId) {
        //权限处理
        //调用搜索服务,远程获取课程媒资信息
        TeachplanMediaPub teachplanMediaPub = courseLearningClient.getmedia(teachplanId);
        if (teachplanMediaPub != null && StringUtils.isNotEmpty(teachplanMediaPub.getMediaUrl())) {
            String mediaUrl = teachplanMediaPub.getMediaUrl();
            return new GetMediaResult(CommonCode.SUCCESS, mediaUrl);
        } else {
            ExceptionCast.cast(CommonCode.FAIL);
            return null;
        }
    }
}
